#include "signal.hpp"
#include <cassert>
#include <cstring>
#include <iostream>
#ifdef _WIN32
    #include <windows.h>
#endif // _WIN32

int main()
{
#ifdef _WIN32
    SetConsoleCP(65001);
    SetConsoleOutputCP(65001);
#endif // _WIN32
    Signal<std::atomic<int>> signal;
    auto data = std::make_shared<std::atomic<int>>(0);

    std::vector<std::thread> threads;
    for (int i = 0; i < 8; ++i)
    {
        threads.emplace_back([&signal]() {
            signal.Connect([](const std::shared_ptr<std::atomic<int>> &data) {
                ThreadFunc::SleepFor(200);
                ++(*data);
            });
        });
    }
    ThreadFunc::SleepFor(200);
    signal(data);
    ThreadFunc::SleepFor(500);
    for (uint32_t i = 0; i < 8; ++i)
    {
        if (threads[i].joinable())
        {
            threads[i].join();
        }
    }
    assert(*data == 8);
    return 0;
}